package com.ssm.zhihu_ssm.service.impl;


import com.ssm.zhihu_ssm.dao.FollowDao;
import com.ssm.zhihu_ssm.dao.UserDAO;
import com.ssm.zhihu_ssm.entity.QuestionAnswerList;
import com.ssm.zhihu_ssm.entity.User;
import com.ssm.zhihu_ssm.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service(value = "followService")
public class FollowServiceImpl implements FollowService {

    @Autowired
    FollowDao followDao;
    @Autowired
    UserDAO userDAO;

    @Override
    public List<User> findUserFollow(int id) {
        int[] ids = followDao.findFollowID(id);
        System.out.print(ids.length);
        List<User> users = new ArrayList<User>();
        for (int x: ids) {
            User user = userDAO.findUserMessage(x);
            user.setPassword(null);
            users.add(user);
        }
        return users;
    }

    @Override
    public List<User> AttentionUserFOLLOWED(int id) {
        int[] ids = followDao.AttentionFollowID(id);
        System.out.println(ids);
        List<User> users = new ArrayList<User>();
        for (int x: ids) {
            User user = userDAO.findUserMessage(x);
            users.add(user);
        }
        return users;
    }

    @Override
    public List<QuestionAnswerList> findFollowQuestion(int id) {
        List<QuestionAnswerList> lists = followDao.findFollowQuestion(id);
        return lists;
    }
}
